import axios from 'axios'
import router from './router'

axios.interceptors.request.use(function(config){
    if(localStorage.getItem('mytoken')){
        config.headers.Authorization=localStorage.getItem('mytoken')
    }
    return config;
},function(error){
    return Promise.reject(error)
})

axios.interceptors.response.use(function(response){
    return response;
},function(error){
    if(error.response.status==401){
        localStorage.removeItem('mytoken')
        router.push('/login')
    }
    return Promise.reject(error)
})
export default axios;